package com.android.monee.domain;

import java.util.Calendar;

import com.android.monee.data.model.Budget;

public class SimpleMensNbCalc implements MensNbCalc {

	@Override
	public int getNbMensuality(Budget budget) {
		int beginMonth;
		int beginYear;
		int termMonth;
		int termYear;
		
		Calendar cal = Calendar.getInstance();
		cal.setTime(budget.getBegin());
		beginMonth = cal.get(Calendar.MONTH);
		beginYear = cal.get(Calendar.YEAR);
		
		cal.setTime(budget.getTerm());
		termMonth = cal.get(Calendar.MONTH);
		termYear = cal.get(Calendar.YEAR);
		
		int beginTermYearDiff = termYear-beginYear;
		
		switch(beginTermYearDiff){
		case 0:
			return termMonth-beginMonth+1;
		case 1:
			return 12-beginMonth + termMonth+1;
		default:
			return 12-beginMonth + termMonth+1 + (beginTermYearDiff-1)*12;
		}
	}

}
